<template>
  <div class="loginstyle">
    <el-card class="box-card"  style="align: 0 padding">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="MemberName">
          <el-input v-model="ruleForm.MemberName"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="PassWord">
          <el-input v-model="ruleForm.PassWord" :show-password="true"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >登录</el-button
          >
          <el-button @click="resetForm('ruleForm')">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import axios from "@/util/axios.js";
export default {
  data() {
    return {
      ruleForm: {
        MemberName: "",
        PassWord: "",
      },
      rules: {
        MemberName: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        PassWord: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    onSubmit() {},
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post("api/Member/Login", this.ruleForm).then((res) => {
            if (res.data.Code == 1) {
              this.$message("用户不存在");
            } else if (res.data.Code == 2) {
              this.$message("密码错误");
            } else {
              localStorage.setItem("userinfo", res.data.sData.Token);
              this.$router.push({ name: "UserView" });
              this.$message("登录成功");
              
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  created() {},
};
</script>
<style>
.loginstyle {
width: 100%;
  background:url('../assets/201571051990813.gif') center center no-repeat ;
  background-size: 100% 100%;
  position: fixed;
 height: 100vh;
}
.box-card {
  width: 480px;
  margin: auto;
  text-align: center;
  height: 250px;
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0.7;
  
  
}
</style> 